package ru.geyes.screw.enums;

import ru.geyes.screw.collections.Option;
import ru.geyes.screw.collections.MapX;
import ru.geyes.screw.collections.HashMapX;
import ru.geyes.screw.collections.ListX;

/**
 * @author alex
 *         date 17.05.2008
 *         time 22:42:55
 */
public class EnumResolver<T extends KeyEnum> {
    private MapX<Long, T> map = new HashMapX();

    private EnumResolver(T[] enums) {
        if (enums != null)
            for (T t : enums)  map.put(t.getKey(), t);
    }

    public Option<T> get(long key) {
        return map.getO(key);
    }

    public ListX<T> toList() {
        return map.valuesX();
    }

    public static <T extends KeyEnum> EnumResolver<T> getInstance(T[] values) {
        return new EnumResolver<T>(values);
    }
}
